package com.oriental.manage.core.schedule;

import com.oriental.manage.core.paging.Pagination;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.pojo.specially.PersonRiskInfo;
import com.oriental.manage.service.specially.PersonRiskInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by dongyy on 2017/5/8.
 */
@Slf4j
@Component
public class RiskInfoSchedule {


    @Autowired
    private PersonRiskInfoService personRiskInfoService;

    /**
     * 定时任务，每天凌晨1点启动
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void run() {
        //启用标记
        Long time = new Date().getTime();
        log.info("定时任务-检查前一天个人风险信息状态，启动。time:",time);
        //检查前一天风险信息是否上报成功，失败即刻进行共享中心进行查询认证是否成功，成功更新本地状态
        ResponseDTO<Pagination<PersonRiskInfo>> responseDTO = new ResponseDTO<Pagination<PersonRiskInfo>>();
        try {
            Pagination<PersonRiskInfo> pagination = new Pagination();
            PersonRiskInfo riskInfo = new PersonRiskInfo();
            personRiskInfoService.queryPage(pagination, riskInfo);
            List<PersonRiskInfo> riskList = new ArrayList<PersonRiskInfo>();
            // 00: 初始 01: 审核通过 02: 审核拒绝 03:上报中 04:上报失败 05:处理失败 06:处理成功
            for(PersonRiskInfo risk : pagination.getList()){
                if(risk.getStatus().equals("03")){
                    riskList.add(risk);
                }
            }

            //构建报文查询共享信息是否有该风险数据

            responseDTO.setSuccess(true);
            responseDTO.setObject(pagination);
        } catch (Exception e) {
            log.error("查询失败", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg(e.getMessage());
        }

        log.info("待办事项创建工作流完成!time:"+time);
    }
}
